#include <stdio.h>
int main()
{
    struct stu_type
    {
        char name[100];
        char num[100];
        int grade;
    } stu[10000];

    int n, i, min = 100, max = 0, j, k;
    scanf("%d", &n);
    for (i = 0; i < n; i++)
    {
        scanf("%s%s%d", &stu[i].name, &stu[i].num, &stu[i].grade);
    }
    for (i = 0; i < n; i++)
    {
        if (min >= stu[i].grade)
        {
            min = stu[i].grade;
            j = i;
        }
        if (max <= stu[i].grade)
        {
            max = stu[i].grade;
            k = i;
        }
    }
    printf("%s %s\n", stu[k].name, stu[k].num);
    printf("%s %s\n", stu[j].name, stu[j].num);
    return 0;
}